package cn.com.dhcc.turbo.service.registry;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.com.dhcc.app.core.exception.DaoException;
import cn.com.dhcc.app.core.exception.ServiceException;
import cn.com.dhcc.app.core.service.BaseService;
import cn.com.dhcc.turbo.dao.registry.OrgInfoDao;
import cn.com.dhcc.turbo.entity.registry.OrgInfo;

/**
 * 行政区信息表service
 * 
 * @日期：2014-5-12 下午3:04:47
 * @作者：张洪涛
 * @版权所有：东华软件
 * @版本：1.0
 */
@Service
public class OrgInfoService extends BaseService {
	@Autowired
	private OrgInfoDao orgInfoDao;

	/**
	 * 一级行政区　省级、流域
	 * 
	 * @return
	 * @throws ServiceException
	 */
	public List<OrgInfo> getProv() throws ServiceException {
		try {
			return orgInfoDao.getProv();
		} catch (DaoException e) {
			throw new ServiceException("获取一级行政区失败", e);
		}
	}

	/**
	 * 二级行政区
	 * 
	 * @param prov 一级行政区代码
	 * @return
	 * @throws ServiceException
	 */
	public List<Map<String, Object>> getCity(String prov)
			throws ServiceException {
		try {
			return orgInfoDao.getCity(prov);
		} catch (DaoException e) {
			throw new ServiceException("获取二级行政区失败", e);
		}
	}

	/**
	 * 三级行政区
	 * 
	 * @param city 二级行政区代码
	 * @return
	 * @throws ServiceException
	 */
	public List<Map<String, Object>> getTown(String city)
			throws ServiceException {
		try {
			return orgInfoDao.getTown(city);
		} catch (DaoException e) {
			throw new ServiceException("获取三级行政区失败", e);
		}
	}

	/**
	 * 二级行政区
	 * 
	 * @param orgCode 行政区代码
	 * @return
	 * @throws ServiceException
	 */
	public List<OrgInfo> getCityByOrgCode(String orgCode)
			throws ServiceException {
		try {
			return orgInfoDao.getCityByOrgCode(orgCode);
		} catch (DaoException e) {
			throw new ServiceException("获取二级行政区失败", e);
		}
	}

	/**
	 * 三级行政区
	 * 
	 * @param orgCode 行政区代码
	 * @return
	 * @throws ServiceException
	 */
	public List<OrgInfo> getTownByOrgCode(String orgCode)
			throws ServiceException {
		try {
			return orgInfoDao.getTownByOrgCode(orgCode);
		} catch (DaoException e) {
			throw new ServiceException("获取三级行政区失败", e);
		}
	}

	public List<OrgInfo> getListByNodeCode(String code) throws ServiceException {
		try {
			return orgInfoDao.getListByNodeCode(code);
		} catch (DaoException e) {
			throw new ServiceException("获取行政区失败", e);
		}
	}
	/**
	 * 获取行政区
	 * @param code
	 * @return
	 * @throws ServiceException
	 */
	public OrgInfo get(String code) throws ServiceException {
		try {
			return orgInfoDao.get(code);
		} catch (DaoException e) {
			throw new ServiceException("获取行政区失败", e);
		}
	}

	public List<OrgInfo> getListByRegionCode()  throws ServiceException {
		try {
			return orgInfoDao.getListByRegionCode();
		} catch (DaoException e) {
			throw new ServiceException("获取行政区失败", e);
		}
	}
	
	public List<OrgInfo> getListByNetType(String netType)  throws ServiceException {
		try {
			return orgInfoDao.getListByNetType(netType);
		} catch (DaoException e) {
			throw new ServiceException("获取行政区失败", e);
		}
	}
	public String getParentCode(String orgCode)  throws ServiceException {
		try {
			return orgInfoDao.getParentCode(orgCode);
		} catch (DaoException e) {
			throw new ServiceException("获取行政区失败", e);
		}
	}
}
